package com.zk.iotgateway.Config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.servlet.config.annotation.*;

import java.nio.charset.Charset;
import java.util.List;

/**
 * ${DESCRIPTION}
 *
 * @author:mn.m
 * @create 2019-07-03 下午 12:00
 **/
@Configuration
public class IotWebAppConfigurer extends WebMvcConfigurationSupport {

    /** 解决跨域问题 **/
    @Override
    public void addCorsMappings(CorsRegistry registry){
        //super.addCorsMappings(registry);
    }

    /** 添加拦截器 **/
    @Override
    protected void addInterceptors(InterceptorRegistry registry){
       /* registry.addInterceptor(new MyInterceptor());*/
        super.addInterceptors(registry);
    }


    /** 这里配置视图解析器 **/
    @Override
    protected void configureViewResolvers(ViewResolverRegistry registry){
        super.configureViewResolvers(registry);
    }

    /** 配置内容裁决的一些选项 **/
    @Override
    protected void configureContentNegotiation(ContentNegotiationConfigurer configurer){
        super.configureContentNegotiation(configurer);
    }

    /** 视图跳转控制器 **/
    @Override
    protected void addViewControllers(ViewControllerRegistry registry) {
        super.addViewControllers(registry);
    }

   /** 静态资源处理 **/
    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {

        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");

    }
    /** 默认静态资源处理器 **/
    @Override
    protected void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        //super.configureDefaultServletHandling(configurer);
        //configurer.enable("stati");
        configurer.enable();
    }
/*

    @Bean
    public HttpMessageConverter<String> responseBodyConverter() {
        StringHttpMessageConverter converter = new StringHttpMessageConverter(Charset.forName("UTF-8"));
        return converter;
    }


    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        super.configureMessageConverters(converters);
        converters.add(responseBodyConverter());
    }
*/


    /** 静态资源处理 **/
   /* @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations("classpath:/META-INF/resources/").setCachePeriod(0);
        registry.addResourceHandler("/static/**")
                .addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/templates/**").addResourceLocations("classpath:/ftl/");
       *//* registry.addResourceHandler("/images/**").addResourceLocations("file:" + imagePath);
        registry.addResourceHandler("/img/**").addResourceLocations("file:" + imagePath);
        registry.addResourceHandler("/file/**").addResourceLocations("file:" + imagePath);*//*
        super.addResourceHandlers(registry);
    }*/


}
